// pages/address/list/index.js
import { reqAddressList, reqDelAddress } from "../../../../../api/address";
import { swipeCellBehavior } from '../../../../../behaviors/swipeCell'
Page({
  // 页面的初始数据
  behaviors:[swipeCellBehavior],
  data: {
    addressList: [],
   
  },

  //删除地址
  async delAddress(event) {
    const { id } = event.currentTarget.dataset;

    const modalRes = await wx.modal({
      content: "您确认删除改地址吗 ？",
    });

    if (modalRes) {
      await reqDelAddress(id);
      wx.toast({ title: "收货地址删除成功" });
      this.getAddressList();
    }
  },

  // 去编辑页面
  toEdit(event) {
    const { id } = event.currentTarget.dataset;

    wx.navigateTo({
      url: `/modules/settingModule/pages/address/add/index?id=${id}`,
    });
  },
  async getAddressList() {
    const { data: addressList } = await reqAddressList();
    // console.log(res);
    this.setData({ addressList });
  },
  onShow() {
    this.getAddressList();
  },
});
